<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html>
<html lang="en">

<head>
	<base href="<%=basePath%>">
	<%@ include file="../../system/admin/top.jsp"%> 
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>新建处方单</title>
    <!--提示框-->
	<script type="text/javascript" src="static/js/jquery.tips.js"></script>
	<script src="static/layer/layer.js"></script><!-- 弹出窗 -->
    <script type="text/javascript">
			$(top.hangge());
			window.top.selectYp = "no";
	</script>    
</head>
  
  <body>
<div class="container-fluid" id="main-container1">


<div id="page-content" class="clearfix">
						
  <div class="row-fluid">


	<div class="row-fluid">
    <!-- 检索患者首个病历  -->
			<form action="cfOrder/chooseYp.do" method="post" name="userForm" id="userForm">
				<table>
					<tr>
						<td>
							<span class="input-icon">
								<input autocomplete="off" id="nav-search-input" type="text" name="name" value="${pd.name}" placeholder="药品编码/名称/拼音码" />
								<i id="nav-search-icon" class="icon-search"></i>
							</span>
						</td>
						<td style="vertical-align:top;"><button class="btn btn-mini btn-light" onclick="find();" title="检索"><i id="nav-search-icon" class="icon-search"></i></button></td>
						<td>
							<span>用量：</span>
							<span class="">
								<input onkeyup="value=value.replace(/[^\d.]/g,'')" name="number" id="number" autocomplete="off" type="text"  placeholder="这里输入药品用量" style="width: 200px;"/>
							</span>
						</td>
						<td style="vertical-align:top;"><a class="btn btn-mini btn-success" onclick="addYp1();" title="确定添加" style="padding:2px 5px;">确定添加</a></td>
					</tr>
					
				</table>
			<!-- 检索  -->
			
			<table id="table_report" class="table table-striped table-bordered table-hover">
				<thead>
					<tr>
						
						<th>序号</th>
						<th>药品编号</th>
						<th>药品名称</th>
						<th>拼音码</th>
						<th>类型</th>
						<th>单位</th>
						<th>用法</th>
						<th>单价</th>
						<th>库存</th>
						<!-- <th class="center">操作</th> -->
					</tr>
				</thead>
				<tbody>
					<!-- 开始循环 -->	
					<c:choose>
						<c:when test="${not empty ypList}">
							<c:forEach items="${ypList}" var="yp" varStatus="vs">
								<tr class='tr'>
									<td class='center' style="width: 30px;">${vs.index+1}</td>
									<td class="ypCode">${yp.ypcode}</td>
									<td class="ypName">${yp.ypname}</td>
									<td class="ypSpell">${yp.ypspell}</td>
									<td class="ypType">${yp.yptype}</td>
									<td class="ypUnit">${yp.ypunit}</td>
									<td class="ypUsage">${yp.ypusage}</td>
									<td class="price">${yp.price }</td>
									<td class="kcTotal">${yp.kcTotal }</td>
									<input type="hidden" class="ypId" value="${yp.id }">
									<!-- <td><a onclick="addYp1();">添加</a></td> -->
								</tr>
							</c:forEach>
						</c:when>
						<c:otherwise>
							<tr class="main_info">
								<td colspan="10" class="center">没有相关数据</td>
							</tr>
						</c:otherwise>
					</c:choose>
					</tbody>
				</table>
				<div class="page-header position-relative">
				<table style="width:100%;">
					<tr>
						<!-- <td style="vertical-align:top;"><a class="btn btn-small btn-success" onclick="add();">新增</a></td> -->
						<td style="vertical-align:top;"><div class="pagination" style="float: right;padding-top: 0px;margin-top: 0px;">${page.pageStr}</div></td>
					</tr>
				</table>
			</div>
			<script type="text/javascript">
				function addYp1(){
					var length = '${ypList.size()}';
					if(length=="1"){
						if($("#number").val()==""){
							$("#number").focus();
							return false;
						}else{
							if(Number($("#number").val())>Number($(".kcTotal").text())){
								layer.alert("库存没那么多！");
								return false;
							}else{
								window.top.selectYp = "has";
								window.top.ypCode = $(".ypCode").text();	//编码
								window.top.ypName = $(".ypName").text();	//名称
								window.top.ypUnit = $(".ypUnit").text();	//单位
								window.top.ypUsage = $(".ypUsage").text();	//用法
								window.top.price = $(".price").text();		//单价
								window.top.kcTotal = $(".kcTotal").text();	//库存
								window.top.ypId = $(".ypId").val();			//药品ID
								window.top.number = $("#number").val();		//用量
								window.top.document.getElementById("_ButtonClose_0").click();
							}
							
						}
					}else{
						 layer.alert("请保留一条药品信息，然后点击添加！");
						return false;
					}
					
				/* 	var obj = new Object();
					obj.ypmc="123";
					obj.sl="456";
					window.top.selectYp = obj; */
				}
			</script>
  </body>
</html>
